package com.module.home.ui.scoringFactors.provider

import android.graphics.Typeface
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.KeyPre
import com.common.app.data.bean.home.ScoringBaseLineItemBean
import com.common.base.app.extras.otherwise
import com.common.base.app.extras.yes
import com.common.base.utils.AppUtils
import com.common.base.utils.MathUtil
import com.common.base.utils.SpUtilsManagement
import com.common.base.utils.SpanUtils
import com.common.base.utils.UnitConversionUtils
import com.common.base.utils.ViewUtils
import com.common.base.widget.CustomTextView
import com.module.home.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/08/28
 *
 * 描述：
 *
 * 修订历史：
 *
 */
class ScoringFactorsHrvItemAdapter(type: String = "") :
    BaseQuickAdapter<ScoringBaseLineItemBean, BaseViewHolder>(R.layout.home_scoring_factors_hrv_item_layout) {

    val mType = type

    override fun convert(holder: BaseViewHolder, item: ScoringBaseLineItemBean) {

        var unitStr = ""
        var currentValue = ""
        var exceededValue = MathUtil.getDoubleValue(MathUtil.negative2positive(item.exceeded_value.toDouble()))

        when (mType) {
            "heart" -> {
                unitStr = AppUtils.getString(R.string.common_times_per_minute_splice)
                currentValue = MathUtil.getDoubleValue(item.current_value.toDouble())
            }

            "hrv" -> {
                unitStr = AppUtils.getString(R.string.common_milliseconds_unit)
                currentValue = MathUtil.getDoubleValue(item.current_value.toDouble())
            }

            "temperature" -> {
                unitStr = if((SpUtilsManagement.getInt(KeyPre.KEY_METERING_UNIT_TEM,0) ==0)) AppUtils.getString(R.string.common_ssd_unit) else AppUtils.getString(R.string.common_hsd_unit)
                currentValue = MathUtil.getDoubleValue(UnitConversionUtils.convertTemperature(item.current_value.toDouble(), UnitConversionUtils.TemperatureUnit.C, if((SpUtilsManagement.getInt(KeyPre.KEY_METERING_UNIT_TEM,0) ==0)) UnitConversionUtils.TemperatureUnit.C else UnitConversionUtils.TemperatureUnit.F))
                exceededValue = MathUtil.getDoubleValue(UnitConversionUtils.convertTemperature(item.exceeded_value.toDouble(), UnitConversionUtils.TemperatureUnit.C, if((SpUtilsManagement.getInt(KeyPre.KEY_METERING_UNIT_TEM,0) ==0)) UnitConversionUtils.TemperatureUnit.C else UnitConversionUtils.TemperatureUnit.F))
            }

            "spo" -> {
                unitStr = AppUtils.getString(R.string.common_bfb_unit)
                currentValue = MathUtil.getDoubleValue(item.current_value.toDouble())

            }

            "breath" -> {
                unitStr = AppUtils.getString(R.string.common_times_per_minute_splice)
                currentValue = MathUtil.getDoubleValue(item.current_value.toDouble())
            }
            else -> {
            }
        }

        SpanUtils.create()
            .addSection("${item.time_period} ${AppUtils.getString(R.string.common_average_unit)}")
            .addForeColorSection(
                "$currentValue$unitStr",
                if (item.exceeded_value>=0) ViewUtils.getColor(R.color.c_f3607b) else ViewUtils.getColor(R.color.c_ff9f40)
            )
            .addSection(AppUtils.getString(R.string.common_comma_splice))
            .addSection(if (item.exceeded_value>=0) AppUtils.getString(R.string.common_come_up_splice) else AppUtils.getString(R.string.common_decline_splice))
            .addForeColorSection(
                "$exceededValue$unitStr",
                if (item.exceeded_value>=0) ViewUtils.getColor(R.color.c_f3607b) else ViewUtils.getColor(R.color.c_ff9f40)
            )
            .showIn(holder.getView(R.id.tvNote))

        holder.setImageResource(R.id.imgBotIcon, if (item.exceeded_value>=0) R.drawable.common_red_warning_icon else R.drawable.common_orange_warning_icon)
    }
}